#!/usr/bin/env node

const { Readable } = require('stream');

class RGB extends Readable {
  constructor(num) {
    super();
    this.num = num; 
    this.current = 0;
  }


  _read() {

    if (this.current >= this.num) {
      this.push(null);
      return;
    }


    const rand = Math.random() * 100;
    if (rand < 60) {
      this.push('R');
    } else if (rand < 75) {
      this.push('G');
    } else {
      this.push('B');
    }

    this.current++;
  }
}

const numSymbols = 5;
const rgb = new RGB(numSymbols);


rgb.on('data', (chunk) => {
  process.stdout.write(chunk);
});

console.log(`开始随机发出 R、G、B 符号，总共 ${numSymbols} 个:`);